$(function () {
    /*刷新页面，所有选框为空*/
    $(".btn-check").prop("checked", false);

    //点击弹窗与关闭
    $(".viewCart-middle").delegate('.delete','click',function () {
        $(".pordShareBg").show();
        $(".delete-single").show().find('.btn-delete')
            .attr('data-id',$(this).attr('data-id'))
            .attr('store-id',$(this).attr('store-id'));
    });
    $(".gl-pop-close").click(function () {
        $(".delete-all,.pordShareBg").hide();
        $(".delete-single").hide().find('.btn-delete').removeAttr('data-id').removeAttr('store-id');
    });


    /*猜你喜欢滚动效果*/
    $(".gx-guess-picScroll").slide({
        titCell: ".hd ul"
        , mainCell: ".bd ul"
        , autoPage: true
        , effect: "leftLoop"
        , autoPlay: true
        , vis: 5
        , trigger: "click"
    });

    /*已选购商品*/
    $(".altogether").click(function () {
        var list_num = $(".altogether-show ul").find("li").length;
        if (list_num > 0) {
            $(".altogether-info").toggle();
            $(this).find("i").toggleClass("on");
        }
    });


    /*加入收藏*/
    $(".viewCart-product .keep").click(function () {
        $this = $(this);
        $(this).css("display", "none");
        $(this).parent().find(".keep-on").css("display", "block");
        var id = $this.parent().parent().attr("data");
        var num = $(".altogether-show ul").find("li").length;
        for (var i = 0; i < num; i++) {
            var list_id = $(".altogether-show ul li").eq(i).attr("data");
            if (id == list_id) {
                $(".altogether-show ul li").eq(i).remove();
            }
        }
        altogether_play();
        delete_li($this);
    })

    $(".viewCart-item.invalid").hover(function () {
        $(this).find(".viewCart-regret").fadeToggle();
    })

    /*已删除商品加入收藏*/
    $(".viewCart-deleted").delegate('.keep','click',function () {
        $this = $(this);
        $(this).hide();
        $(this).siblings(".keep-on").show();
        delete_li($this);  
    })

    /*去结算栏浮动*/
    var wtop = document.documentElement.clientHeight;  //浏览器高度
    var boxheight=$(".viewCart-middle").height();  //商品容器高度
    var vtop = $(document).scrollTop();  //页面当前离顶部距离
    var cartTop = boxheight+251;  //结算栏离顶部距离
    if (cartTop > wtop && (cartTop-wtop) > vtop) {
        $(".viewCart-bottom").addClass("on");
    };
    $(window).scroll(function () {
        var vtop = $(document).scrollTop();
        if (vtop > (cartTop-wtop)) {
            $(".viewCart-bottom").removeClass("on");
        } else {
            $(".viewCart-bottom").addClass("on");
        }
    })


    /*猜你喜欢点击加入购物车*/
    $(".gx-guess-list .get-cart").click(function () {
        var $this=$(this).parents("li").find(".get-success");
        $this.show();
        setTimeout(function(){
            $this.hide();
        },2000) 
    })

})

/*移到收藏夹*/
function delete_li($this) {
    setTimeout(function () {
        $this.parents(".deleted-item").hide();
        var length = $this.parent().parent().parent().find(".viewCart-item").length;
        if (length < 2) {
            $this.parents(".viewCart-shop").remove();
        } else {
            $this.parents(".viewCart-item").remove();
        }
    }, 2000)
}

/*修改商品后执行*/
function altogether_play() {
    $(".altogether-show").slide({
        titCell: ".hd ul"
        , mainCell: ".bd ul"
        , autoPage: true
        , effect: "left"
        , scroll: 10
        , vis: 10
        , pnLoop: false
    });
    var info_num = $(".altogether-show ul").find("li").length;
    if (info_num > 0) {
        $(".viewCart-bottom").find(".btn-dete").addClass("on");
        if (info_num > 10) {
            $(".altogether-show .prev,.altogether-show .next").css("display", "block");
        } else {
            $(".altogether-show .prev,.altogether-show .next").css("display", "none");
        }
    } else {
        $(".viewCart-bottom").find(".btn-dete").removeClass("on");
        $(".altogether-show .prev,.altogether-show .next").css("display", "none");
        $(".altogether-info").hide();
        $(this).find("i").toggleClass("on");
    }
};
